package com.bjpowernode.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SomeServlet implements Servlet {

	private ServletConfig config;

	@Override
	public void destroy() {
	}

	@Override
	public ServletConfig getServletConfig() {
		return config;
	}

	@Override
	public String getServletInfo() {
		return null;
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		this.config = config;
		System.out.println("config=" + config);
	}

	@Override
	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
		String servletName = config.getServletName();
		System.out.println("servletName=" + servletName);
		ServletContext servletContext = config.getServletContext();
		System.out.println("servletContext=" + servletContext);

		System.out.println(config.getInitParameter("name"));
		System.out.println(config.getInitParameter("address"));
		System.out.println("=========================");
		Enumeration<String> initParameterNames = config.getInitParameterNames();
		while (initParameterNames.hasMoreElements()) {
			String nextElement = initParameterNames.nextElement();
			System.out.println("key=" + nextElement + ",value=" + config.getInitParameter(nextElement));
		}
	}

}
